home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dme / mods.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  3KB  |  183 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  KTS.C
  9.  *
  10.  *  Additional DME commands written by Kevin T. Seghetti fixed up and
  11.  *  incorporated by Matt Dillon 17 April 1988.
  12.  */
  13.  
  14. #include "defs.h"
  15. #include <intuition/intuitionbase.h>
  16.  
  17. Prototype void PMAdd (void);
  18. Prototype void PMRem (void);
  19. Prototype void PMKill (struct _ED *);
  20. Prototype int do_pushmark (void);
  21. Prototype void do_popmark (void);
  22. Prototype void do_swapmark (void);
  23. Prototype void do_purgemark (void);
  24. Prototype void do_ping (void);
  25. Prototype void do_pong (void);
  26. Prototype void do_undo (void);
  27.  
  28. #define BLOCKDEPTH  5
  29. #define PINGDEPTH   10
  30.  
  31. static long BSstack[BLOCKDEPTH];
  32. static long BEstack[BLOCKDEPTH];
  33. static ED   *Bp[BLOCKDEPTH];
  34. static int  CurrDepth = 0;
  35.  
  36. static long PingLine[PINGDEPTH];
  37. static long PingCol[PINGDEPTH];
  38. static ED   *PingWin[PINGDEPTH];
  39.  
  40. void
  41. PMAdd()
  42. {
  43. }
  44.  
  45. void
  46. PMRem()
  47. {
  48. }
  49.  
  50. void
  51. PMKill(ep)
  52. ED *ep;
  53. {
  54.     short i, j;
  55.  
  56.     for (i = 0; i < PINGDEPTH; ++i) {       /*  remove ping-pong marks  */
  57.     if (PingWin[i] == ep)
  58.         PingWin[i] = NULL;
  59.     }
  60.     for (i = j = 0; i < CurrDepth; ++i) {   /*  remove block marks      */
  61.     Bp[j] = Bp[i];
  62.     if (Bp[i] != ep)
  63.         ++j;
  64.     }
  65.     CurrDepth = j;
  66. }
  67.  
  68. do_pushmark()
  69. {
  70.     text_sync();
  71.     if (blockok()) {
  72.     if (CurrDepth == BLOCKDEPTH) {
  73.         title("pushmark: stack limit reached");
  74.         return(-1);
  75.     }
  76.     BSstack[CurrDepth] = BSline;
  77.     BEstack[CurrDepth] = BEline;
  78.     Bp[CurrDepth] = BEp;
  79.  
  80.     ++CurrDepth;
  81.     text_redrawblock(0);
  82.     }
  83.     return(0);
  84. }
  85.  
  86. void
  87. do_popmark()
  88. {
  89.     text_sync();
  90.  
  91.     if (!CurrDepth) {           /*  no error message on purpose */
  92.     text_redrawblock(0);    /*  remove any existing block   */
  93.     return;
  94.     }
  95.     text_redrawblock(0);
  96.     --CurrDepth;
  97.     BSline = BSstack[CurrDepth];
  98.     BEline = BEstack[CurrDepth];
  99.     BEp = Bp[CurrDepth];
  100.     if (BEp == NULL || BEline >= BEp->Lines) {
  101.     BEp = NULL;
  102.     BSline = BEline = -1;
  103.     } else
  104.     text_redrawblock(1);
  105. }
  106.  
  107. void
  108. do_swapmark()
  109. {
  110.     short i;
  111.     long *ptmp;
  112.     long tmp;
  113.  
  114.     if (do_pushmark() < 0)
  115.     return;
  116.     i = CurrDepth - 2;
  117.     if (i >= 0) {
  118.     ptmp = PingLine + i;
  119.     tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  120.     ptmp = PingCol + i;
  121.     tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  122.     ptmp = (long *)PingWin + i;
  123.     tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  124.     }
  125.     do_popmark();
  126. }
  127.  
  128. void
  129. do_purgemark()
  130. {
  131.     CurrDepth = 0;
  132. }
  133.  
  134. void
  135. do_ping()
  136. {
  137.     uword num = atoi(av[1]);
  138.  
  139.     if (num >= PINGDEPTH) {
  140.     title("ping: out of range");
  141.     return;
  142.     }
  143.     PingLine[num]= Ep->Line;
  144.     PingCol[num] = Ep->Column;
  145.     PingWin[num] = Ep;
  146.     title("Line marked");
  147. }
  148.  
  149. void
  150. do_pong()
  151. {
  152.     uword num = atoi(av[1]);
  153.     extern IBASE *IntuitionBase;
  154.  
  155.     text_sync();
  156.     if (num < 0 || num >= PINGDEPTH || !PingWin[num]) {
  157.     title("pong: range error or nothing marked");
  158.     return;
  159.     }
  160.     text_cursor(1);
  161.     text_switch(PingWin[num]->Win);
  162.     text_cursor(0);
  163.  
  164.     if (IntuitionBase->ActiveWindow != Ep->Win) {
  165.     WindowToFront(Ep->Win);
  166.     ActivateWindow(Ep->Win);
  167.     }
  168.     if ((Ep->Line = PingLine[num]) >= Ep->Lines) {
  169.     PingLine[num] = Ep->Line = Ep->Lines - 1;
  170.     }
  171.     Ep->Column = PingCol[num];
  172.     text_load();
  173.     text_sync();
  174. }
  175.  
  176. void
  177. do_undo()
  178. {
  179.     text_load();
  180.     text_redisplaycurrline();
  181. }
  182.  
  183.